package com.study.d030animation;

import javafx.animation.Animation;
import javafx.animation.FadeTransition;
import javafx.animation.FillTransition;
import javafx.animation.Interpolator;
import javafx.animation.ParallelTransition;
import javafx.animation.RotateTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Point3D;
import javafx.scene.Scene;
import javafx.scene.chart.Axis;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/** 并行动画
*@description
*@author xtayhame
*date 2020年3月22日
*version
*since v1.0
*/
public class ParallelTransitionMain  extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();
		HBox hBox = new HBox(20);
		Button b1=new Button("播放");
		Button b2=new Button("暂停");
		Button b3=new Button("停止");
		Button b4=new Button("设置加速");
		Button b7=new Button("从第二个点开始");

		Rectangle rectangle = new Rectangle(70, 70,Paint.valueOf("#EE82EE55"));

		hBox.getChildren().addAll(b1,b2,b3,b4,b7);
		anchorPane.getChildren().addAll(hBox,rectangle);
		AnchorPane.setTopAnchor(rectangle, 70.0);
		AnchorPane.setLeftAnchor(rectangle, 70.0);

		AnchorPane.setTopAnchor(rectangle, 80.0);
		AnchorPane.setLeftAnchor(rectangle, 100.0);

		stage.setScene(new Scene(anchorPane, 800, 600));
		stage.show();

		FillTransition ts = new FillTransition();
		ts.setDuration(Duration.seconds(1));
		ts.setFromValue(Color.valueOf("#FFC125"));
		ts.setToValue(Color.valueOf("#104E8B"));
		ts.setDuration(Duration.seconds(0.5));

		FadeTransition ft = new FadeTransition();
		ft.setFromValue(1);
		ft.setToValue(0.5);
		ft.setDuration(Duration.seconds(0.5));

		TranslateTransition tt= new TranslateTransition();
		tt.setFromX(0);
		tt.setToX(300);
		tt.setDuration(Duration.seconds(5));

		ScaleTransition st = new ScaleTransition();
		st.setFromX(1);
		st.setToX(1.5);
		st.setDuration(Duration.seconds(1));

		RotateTransition rt = new RotateTransition();
		rt.setFromAngle(0);
		rt.setToAngle(720);
		rt.setDuration(Duration.seconds(5));


		ParallelTransition ps= new ParallelTransition();
		ps.setNode(rectangle);
		ps.getChildren().addAll(tt,rt,st,ft,ts);
		ps.setCycleCount(Animation.INDEFINITE);
		ps.setAutoReverse(true);


		//设置差速器
		ts.setInterpolator(Interpolator.LINEAR);

		b1.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				ps.play();
			}
		});
	}



}

